﻿<m:ElevatorAutomaton 
    x:Class="Rhizome.QuickStart.Elevator.Model.UpDown" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:m="clr-namespace:Rhizome.QuickStart.Elevator.Model" 
	xmlns:r="clr-namespace:Rhizome.Model;assembly=Rhizome.Core" 
    InitialState="Idle" 
    >

    <m:ElevatorAutomaton.Edges>

        <r:Edge State="Idle">
            <r:Transition Event="Up" State="MovingUp"  />
            <r:Transition Event="Down" State="MovingDown" />
        </r:Edge>

        <r:Edge State="MovingDown">
            <r:Transition Event="Canceled" State="Idle" />
            <r:Transition Event="Stop" State="Idle" />
        </r:Edge>

        <r:Edge State="MovingUp">
            <r:Transition Event="Canceled" State="Idle" />
            <r:Transition Event="Stop" State="Idle" />
        </r:Edge>

    </m:ElevatorAutomaton.Edges>

    <m:ElevatorState Id="Idle">
        <r:Trigger Property="UpChecked" Value="True" Action="CastEvent Up" />
		<r:Trigger Property="DownChecked" Value="True" Action="CastEvent Down" />
    </m:ElevatorState>

    <m:ElevatorState Id="MovingUp">

		<r:Trigger Property="Position" Value="10.0"  Action="CastEvent Stop" />
		<r:Trigger Property="UpChecked" Value="False" Action="CastEvent Canceled" />

		<r:DoubleCounter Property="Position" Period="00:00:00.1" Step="+1" />

		<r:OnExit Action="UpChecked=False" />
    </m:ElevatorState>

    <m:ElevatorState Id="MovingDown">

		<r:Trigger Property="Position" Criterion="Position == 0.0" Action="CastEvent Stop" />
		<r:Trigger Property="DownChecked" Criterion="DownChecked == False" Action="CastEvent Canceled"/>

		<r:DoubleCounter Property="Position" Period="00:00:00.1" Step="-1" />

		<r:OnExit Action="DownChecked=False" />
	</m:ElevatorState>


</m:ElevatorAutomaton>